const mongoose = require('mongoose');
const bcrypt = require('bcrypt');
const admin = require('../route/admin');

//  创建用户集合规则
const userSchema = new mongoose.Schema({
    username: {
        type: String,
        require: true,
        minlength: 2,
        maxlength: 20
    },
    email: {
        type: String,
        //  保证邮箱地址不重复
        unique: true,
        require: true
    } ,
    password: {
        type: String,
        require: true
    },
    role: {
        type: String,
        require: true
    },
});
//  创建集合
const User = mongoose.model('User', userSchema);


// //  创建密码加密函数
// async function passwordBcrypt() {
//     //  生成随机字符串  返回promise对象
//     const  salt = await bcrypt.genSalt;
//     //  生成加密密码
//     let password = await bcrypt.hash('123456', salt);
//     const user = await User.create({
//         username: 'zhangsan',
//         password: password,
//         role: admin
//     });
// }
// //  创建初始用户
// passwordBcrypt();

//  将用户集合导出

module.exports = {
    User: User
}